<?php
    @include_once("conn.php");

    $key = $_GET["key"];  // 搜索的关键词
    $orderCol = $_GET["orderCol"];  // 排序的列名 (id,chinese,total)
    $orderType = $_GET["orderType"];  // 排序的列名 (asc desc)

    if(!($orderCol&&$orderType)){
        argErr();
    }   

    //  页码 pageIndex  每页显示数据:showNum
    // 第1页  limit 0,5  
    // 第2页  limit 5,5  
    // 第3页  limit 10,5  
    
    
    // $sql = "select id,name,class,chinese,math,english,chinese+math+english as total from `grade` where name like '%$key%' order by $orderCol $orderType ";

    $sql = "select id,name,class,chinese,math,english,chinese+math+english as total from `grade` where name like '%$key%' order by $orderCol $orderType ";

    $result = mysqli_query($conn,$sql);

    $all = array();
    while($item = mysqli_fetch_assoc($result)){

        // 数据预处理
        $item["chinese"] =$item["chinese"] *1;
        $item["math"] =$item["math"] *1;
        $item["english"] =$item["english"] *1;
        $item["total"] =$item["total"] *1;

        array_push($all,$item);
    }

    $obj = array();
    if(count($all)>0){
        $obj["status"] = true;
        $obj["detail"] = "ok";
        $obj["list"] = $all;
    }else{
        $obj["status"] = false;
        $obj["detail"] = "暂无数据";
    }

    echo json_encode($obj);

?>